<?php 
Class photoController extends appController
{
	
	public function index()
	{
		if(in_array($_GET['code'],array('wardrobe')))
		{
			//$this->check_member();
		}
		
		$page=$_GET['page']>0?intval($_REQUEST['page']):1;
		$cache_id = $_GET['code'] . '-' . DEFAULT_LANG. '-' .session('user_id');;
		
		
		$cache_id = sprintf('%X', crc32($cache_id));
		if (!$this->is_cached($_GET['code'].'.html', $cache_id))
		{
			$app=Model('app');
			if(!$id=$app->code_to_id($_GET['code']))
			{
				hy_404();
			}
			
			if($_GET['code']=='storeimage')
			{
				$subclass=$app->getSubClass($id);
				$this->assign('sub',$subclass);
			}
			$pcat=$app->getPClass($id);
			$cat=$app->getCurClass($id);
			
			$config[c]=array('site_name'=>$cat['name'].'-'.$app->get_cfg('site_name'));
			$this->assign('cat',$cat);
			$this->assign_global($config);
			if($_GET['code']=='birthdaty'||$_GET['code']=='integral')
			{
				$page_size=8;
			}
			else 
			{
			    $page_size=30;
			}
			
		    $art_list=Model('photo')->get_photo_list($page,$id,$page_size);
		
		
	    
		$this->assign('photo_list',$art_list['data']);
		$this->assign('show_page',$art_list['pagelink']);
		}
	        if($pcat['code']==storeimage)
			{
				$tpl='store_view.html';
			}
			else 
			{
				$tpl=$_GET['code'].'.html';
			}
		$this->display($tpl,$cache_id);
	}
	public function download()
	{
		$id=intval($_GET['id']);
		if($id)
		{
			$photo=Model('photo');
		$art_info=$photo->get_photo($id);
		
		   if($art_info['original_pic'])
		   {
	  header('Content-type: image/jpeg');
		
        header("Content-Disposition: attachment; filename=".basename($art_info['original_pic']));
      
        
      //  echo '<img src="'.$art_info['original_pic'].'"/>';
        
        @readfile('http://'.$_SERVER['HTTP_HOST'].$art_info['original_pic']);
exit;
		   }
		}
		
	}
	public function view()
	{
		
		$id=isset($_GET['id'])?intval($_GET['id']):'';
		$cache_id = $id . '-' . DEFAULT_LANG. '-' .session('user_id');;
		
		//$art_cat=$photo->photo_cat($id);
		$cache_id = sprintf('%X', crc32($cache_id));
		if (!$this->is_cached('phoro_view.html', $cache_id))
		{
			$photo=Model('photo');
			$art_info=$photo->get_photo($id);
			$app=Model('app');
			$config[c]=array('site_name'=>$art_info['title'].'-'.$app->get_cfg('site_name'));
				$this->assign_global($config);
               
              
                $this->assign('photo', $art_info);
		}
		
		$tpl='photo_view.html';
		$this->display($tpl,$cache_id);
	}
}